//
//  LayerPUView.m
//  Dispatch
//
//  Created by hyeyeon on 14. 1. 14..
//  Copyright (c) 2014년 hyeyeon. All rights reserved.
//

#import "LayerPUView.h"
#import "AppDelegate.h"

@implementation LayerPUView
@synthesize delegate;

+(LayerPUView *)getLayerPUViewWithDelegate:(id)_delegate{
    return [[LayerPUView alloc] initWithFrame:CGRectMake(0, 0, mySize.width, mySize.height) andDelegate:_delegate];
}

- (id)initWithFrame:(CGRect)frame andDelegate:(id)_delegate
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
        self.delegate = _delegate;
        [self makeWebView];
    }
    return self;
}

-(void)makeWebView{
    
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, myOrginY, mySize.width, mySize.height-myStatusBarHeight)];
    [self addSubview:_webView];
    
    
    //web뷰에서 터치이벤트
    //        UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleDoubleTap:)];
    //
    //        singleFingerDTap.numberOfTapsRequired = 1;
    //        singleFingerDTap.delegate = self;
    //        [_webView addGestureRecognizer:singleFingerDTap];
    
    UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(mySize.width-31-10, 10, 31, 31)];
    [closeBtn setImage:[UIImage imageNamed:@"intro_btn_x"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:closeBtn];
}

#pragma mark - 웹URL 요청

-(void)appearWebURL:(NSString*)url{
    
    if (![self superview]) {
        [appDelegate.window addSubview:self];
    }
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

#pragma mark - 버튼클릭

-(void)closeBtnClick:(id)sender{
    [self removeLayerPUView];
}

#pragma mark - 닫기
-(void)removeLayerPUView{
    
    if ([self superview]) {
        [self removeFromSuperview];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
